package com.qidian.mes.qc.service.impl;/**
 * ClassName:CheckItemServiceImpl
 * Package:com.qidian.mes.qc.service.impl
 **/

import com.qidian.mes.pojo.CheckItem;
import com.qidian.mes.qc.mapper.CheckItemMapper;
import com.qidian.mes.qc.service.CheckItemService;
import com.qidian.mes.util.dot.PagerDTO;
import com.qidian.mes.util.pojo.QdResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Author ppc
 * @Conpany study
 * @Description:
 * @Time 2024/4/5 14:10
 *
 **/
@Service
public class CheckItemServiceImpl implements CheckItemService {
    @Autowired
    private CheckItemMapper checkItemMapper;


    @Override
    public QdResult updateByTemplate(CheckItem checkItem) {
        checkItemMapper.updateByTemplate(checkItem);
        return QdResult.success();
    }

    @Override
    public QdResult saveByTemplate(CheckItem checkItem) {
        checkItemMapper.insertByTemplate(checkItem);
        return QdResult.success();
    }

    @Override
    public QdResult deletes(String[] checkItemIds) {
        checkItemMapper.deletes(checkItemIds);
        return QdResult.success();
    }

    @Override
    public QdResult delete(String checkItemId) {
        checkItemMapper.delete(checkItemId);
        return QdResult.success();
    }

    @Override
    public QdResult update(CheckItem checkItem) {
        checkItemMapper.update(checkItem);
        return QdResult.success();
    }

    @Override
    public QdResult save(CheckItem checkItem) {
        checkItemMapper.insert(checkItem);
         return QdResult.success();
    }

    @Override
    public QdResult<List<CheckItem>> queryAll() {
        return QdResult.success(checkItemMapper.queryAll());
    }

    @Override
    public QdResult selectByCheckItemId(String checkItemId) {
       return QdResult.success(checkItemMapper.selectByCheckItemId(checkItemId));
    }

    @Override
    public QdResult<PagerDTO<CheckItem>> queryByPage(CheckItem checkItem, int page, int limit) {
        PagerDTO<CheckItem> pagerDTO = new PagerDTO<>();
        pagerDTO.setLimit(limit);
        pagerDTO.setPage(page);
        pagerDTO.setTotal(checkItemMapper.count(checkItem));
        pagerDTO.setData(checkItemMapper.queryByPage(checkItem,(page-1)*limit,limit));
        return QdResult.success(pagerDTO);
    }

    @Override
    public QdResult<PagerDTO<CheckItem>> queryByPageTemplate(String templateId, int page, int limit) {
        PagerDTO<CheckItem> pagerDTO = new PagerDTO<>();
        pagerDTO.setLimit(limit);
        pagerDTO.setPage(page);
        pagerDTO.setTotal(checkItemMapper.countTemplate(templateId));
        pagerDTO.setData(checkItemMapper.queryByPageByTemplateId(templateId,(page-1)*limit,limit));
        return QdResult.success(pagerDTO);
    }
}
